#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <binder/Parcel.h>
#include <cutils/properties.h>
#include <signal.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include "sqrclient.h"


//#ifndef LOG_TAG
#define LOG_TAG "sqr_service"
//#endif

#include <cutils/log.h>

namespace android{ 
	sp<IBinder> m_ib;

	SQR::SQR(){
		getSQRService();
	}

	const void SQR::getSQRService()
	{
		sp<IServiceManager> sm = defaultServiceManager();
		m_ib = sm->getService(String16("com.aspros.sqr"));
		ALOGE("SQR:getSQRService %p\n", sm.get());

		if (m_ib == 0){
			ALOGW("SQRService not published, wating...");
		}

		return;
	}

	int SQR::execute(int n)
	{
		Parcel data, reply;
		data.writeInt32(n);
		ALOGE("SQR::execute\n");
		
		m_ib->transact(1, data, &reply);
		int num = reply.readInt32();
		return num;
	}
}

using namespace android;

int main(int argc, char** argv)
{
	ALOGE("sqrclient enentry.\n");
	SQR* sqr = new SQR();
	int num = sqr->execute(5);
	
	ALOGE("SQR execute ret=%d\n", num);
	printf("SQR execute ret=%d\n", num);
	
	return 0;
}

